package com.ruoyi.backend.service.Impl;

import com.ruoyi.backend.mapper.RestorationProjectMapper;
import com.ruoyi.backend.pojo.RestorationProject;
import com.ruoyi.backend.service.RestorationProjectService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.backendEnum.RestorationProjectException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RestorationProjectServiceImpl implements RestorationProjectService {

    @Autowired
    private RestorationProjectMapper restorationProjectMapper;

    @Override
    public List<RestorationProject> search(String mineId, String restorationName) {
        List<RestorationProject> restorationProjectList = restorationProjectMapper.search(mineId, restorationName);
//        if (restorationProjectList.isEmpty()){
//            throw new ServiceException(RestorationProjectException.RESTORATION_PROJECT_NOT_FOUND);
//        }
        return restorationProjectList;
    }

    @Override
    public void upload(RestorationProject restorationProject) {
        restorationProjectMapper.upload(restorationProject);
    }

    @Override
    public void delete(Integer restorationId) {
        if (restorationProjectMapper.getRestorationCount(restorationId) == 0){
            throw new ServiceException(RestorationProjectException.RESTORATION_PROJECT_NOT_EXIST);
        }
        restorationProjectMapper.delete(restorationId);
    }

    @Override
    public void update(RestorationProject restorationProject) {
        if (restorationProjectMapper.getRestorationCount(restorationProject.getRestorationId()) == 0){
            throw new ServiceException(RestorationProjectException.RESTORATION_PROJECT_NOT_EXIST);
        }
        restorationProjectMapper.update(restorationProject);
    }

    @Override
    public List<RestorationProject> searchAll() {
        return restorationProjectMapper.searchAll();
    }
}
